from datetime import datetime

import numpy as np
import pandas as pd


class Utils:
    @staticmethod
    def format_day_str(date_str):
        time = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S")
        return time.strftime("%Y-%m-%d 00:00:00")

    @staticmethod
    def format_time_2_day(time):
        return time.strftime("%Y-%m-%d 00:00:00")

    @staticmethod
    def is_predict_right(predict, target):
        return target[np.argmax(predict)] == 1

    @staticmethod
    def is_predict_right_one_hot(predict_val, expect):
        return expect == round(predict_val)

    @staticmethod
    def format_time_str_2_day(date_str):
        time = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S")
        return time.strftime("%Y-%m-%d 00:00:00")

    @staticmethod
    def parse_time(date_str):
        time = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S")
        return time

    @staticmethod
    def read_series(array, lookup):
        series = []
        for i in range(len(array)):
            if i > lookup - 1:
                series.append(array[i - lookup:i])
        return series
